# åªå£°ä¿¡å·
import torch
from apps.exp.exp_config import ExpConfig as EG

class NoiseSignal(object):
    def __init__(self):
        self.name = 'apps.exp.noise_signal.NoiseSignal'

    @staticmethod
    def generate_signal(y:torch.Tensor, SNR_dB:float) -> torch.Tensor:
        signal_power = torch.mean(torch.abs(y)**2)
        noise_power = signal_power / (10**(SNR_dB/10))
        noise = torch.sqrt(noise_power/2) * (torch.randn(EG.N, dtype=torch.float32))
        imag_part = torch.zeros_like(noise)
        noise = torch.complex(noise, imag_part)
        # noise += torch.sqrt(noise_power/2) * torch.randn(EG.N, dtype=torch.float32)
        return noise